#include "MainScene.h"
#include "AppMacros.h"

#include "Level/Level.h"
USING_NS_CC;


CCScene* HelloWorld::scene()
{
    // 'scene' is an autorelease object
    CCScene *scene = CCScene::create();
    
    // 'layer' is an autorelease object
    HelloWorld *layer = HelloWorld::create();

    // add layer as a child to scene
    scene->addChild(layer);

    // return the scene
    return scene;
}

// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

	/////////////////////////////
	// 2. Create level
	auto level = new Level();
	level->initWorld(this);
	setTouchEnabled(false);
	CCDirector::sharedDirector() -> getTouchDispatcher() -> addTargetedDelegate( this, 0, true);
    return true;
}

bool HelloWorld::ccTouchBegan( cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent )
{
	_prevTouchPos = pTouch->getLocation();
	return true;
}

void HelloWorld::ccTouchMoved( cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent )
{
	setPosition(ccpAdd(getPosition(), ccpSub(pTouch->getLocation(), _prevTouchPos)));
	_prevTouchPos = pTouch->getLocation();
}

void HelloWorld::ccTouchEnded( cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent )
{

}
